import * as api from "./api";
import { CreateCrudOptionsProps, CreateCrudOptionsRet, dict } from "@fast-crud/fast-crud";
import { request } from "/@/api/service";

export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  const pageRequest = async (query) => {
    return await api.GetList();
  };
  const delRequest = async ({ row }) => {
    console.log(row);
    return await api.DelObj(row.id);
  };
  const addRequest = async ({ form }) => {
    return await api.AddObj(form);
  };
  const editRequest = async ({ form, row }) => {
    form.id = row.id;
    return await api.UpdateObj(form);
  };
  return {
    crudOptions: {
      request: {
        pageRequest,
        delRequest,
        addRequest,
        editRequest
      },
      columns: {
        id: {
          title: "ID",
          type: "number",
          column: { width: 60 },
          form: { show: false }
        },
        userId: {
          title:'用户名',
          key: "userId",
          column:{
            show:true
          },
          type: "dict-select",
          dict: dict({
            getData({ dict }) {
              return request({
                url: "http://localhost:8000/community/users/",
                method: "get"
              });
            },
            value:'id',
            label:'username'
          })
        },
        catagory: {
          title: "账单类别",
          type: "dict-select",
          dict: dict({
            data: [
              { label: "物业费", value: "property" },
              { label: "停车费", value: "parking" },
              { label: "电费", value: "electric" },
              { label: "水费", value: "water" }
            ]

          })
        },
        amount: {
          title: "金额",
          type: "number",
          form: {
            component: { props: { precision: 2, min: 0 } }
          }
        },
        paid: {
          title: "账单状态",
          type: "dict-switch",
          column:{
            cellRender:(scope)=>{
              if(scope.value===true){
                return "已支付"
              }
              return '未支付'
            }
          }
        },
        description: {
          title: "描述",
          type: "string",
          form: {
          }
        },
        billtime: {
          title: "账单时间",
          type: "datetime",

        }
      }
    }
  };
}
